import { DailyListNormal } from "./DailyListNormal";
import { DailyBossItem } from "../item/DailyBossItem";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { Language } from "../../../../../extend/language/Language";
import { DateParser } from "../../../../common/tools/DateParser";
import { ClockManager } from "../../../manager/ClockManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { BossTitleBar } from "../titleBar/BossTitleBar";
import { BossAwardList } from "../reward/BossAwardList";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { Cache } from "../../../cache/Cache";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
type int = number;
//class DailyBossList
    
    export  class DailyBossList extends DailyListNormal
    {
        constructor()
        {
            super();
            return;
        }

        public updateRefreshData(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc1 of loc4) 
            {
                loc2 = this.getBossItemByBossId(loc1.wildBossId);
                if (!loc2) 
                {
                    continue;
                }
                loc2.updateBossRefreshInfo(loc1);
            }
            return;
        }

        protected getBossItemByBossId(arg1: int): DailyBossItem
        {
            var loc1=0;
            var loc3=null;
            var loc2=_bodySprite.length;
            while (loc1 < loc2) 
            {
                if ((loc3 = _bodySprite.getItemAt(loc1) as DailyBossItem) && loc3.info.type == arg1) 
                {
                    return loc3;
                }
                ++loc1;
            }
            return null;
        }

        protected startTimer(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer(1);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
            }
            if (!this._timer.running) 
            {
                this._timer.start();
            }
            return;
        }

        protected stopTimer(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.isDelete = false;
            }
            return;
        }

        protected onTimerHandler(arg1: SecTimer): void
        {
            this._timerTxt.text = Language.getString(380004) + DateParser.parse(ClockManager.instance.nowDate, "hh：mm：ss");
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _bg.height = 374;
            this._timerTxt = new Object /* flash.text.TextField */();
            this._timerTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timerTxt.width = 120;
            this._timerTxt.mouseEnabled = false;
            this._timerTxt.x = 170;
            this._timerTxt.y = height - 22;
            this._timerTxt.filters = [FilterConst.nameGlowFilter];
            this._timerTxt.textColor = 65280;
            addChild(this._timerTxt);
            return;
        }

        protected /* override */ initWidth(): void
        {
            super.initWidth();
            _listHeight = 342;
            return;
        }

        protected /* override */ createTitleBar(): void
        {
            _titleBar = new BossTitleBar(_titleWidth);
            _titleBar.x = 20;
            _titleBar.y = 5;
            addChild(_titleBar);
            return;
        }

        protected /* override */ createAwardList(): void
        {
            _dailyAwardList = new BossAwardList(width - _listWidth - 4, height);
            _dailyAwardList.x = _listWidth + 4;
            _dailyAwardList.y = 0;
            addChild(_dailyAwardList);
            return;
        }

        public /* override */ updateData(arg1: Array<any>, arg2: int, arg3: int=0): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            this.dispose();
            if (arg1 != null) 
            {
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    loc3 = arg1[loc1];
                    loc4 = ObjectPool.getObject(DailyBossItem);
                    if (loc3 != null) 
                    {
                        loc4.updateData(loc3);
                        (loc4 as DailyBossItem).updateBossRefreshInfo(Cache.instance.daily.getBossRefreshInfoByBossId(loc3.type));
                        _bodySprite.addItem(loc4);
                        if (loc1 == 0) 
                        {
                            _dailyAwardList.updateData(loc3);
                            loc4.mouseDown(true);
                            _lastItem = loc4;
                        }
                    }
                    ++loc1;
                }
                if (loc2 <= 4) 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.OFF;
                }
                else 
                {
                    _scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
                }
            }
            _bodySprite.redraw();
            _scrollPane.refreshPane();
            _scrollPane.update();
            _scrollPane.horizontalScrollPosition = 0;
            this.startTimer();
            selectedItemByType(arg3);
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            this.stopTimer();
            this._timerTxt.text = "";
            return;
        }

        protected /* var */_timer: SecTimer;

        protected /* var */_timerTxt: Object /* flash.text.TextField */;
    }
